#!/bin/bash

# Set PATH explicitly to include git location
export PATH=$PATH:/home/git/bin

set +e

log_file="/opt/wuziToYouzi.log"

cd /home/mycookbook >>"$log_file" 2>&1

rm -rf goods.json* >>"$log_file" 2>&1
git fetch origin >>"$log_file" 2>&1
git reset --hard origin/$(git rev-parse --abbrev-ref HEAD) >>"$log_file" 2>&1


if [ -e "goods.json-wuzi" ]; then
    # 文件存在，不执行任何操作
    echo "goods.json-wuzi file exist" >>"$log_file" 2>&1
    exit 0
else
    # 文件不存在，执行相关命令
    mv goods.json goods.json-wuzi >>"$log_file" 2>&1
    mv goods.json-youzi goods.json >>"$log_file" 2>&1

    git add . >>"$log_file" 2>&1
    git commit -m "update" >>"$log_file" 2>&1
    git push >>"$log_file" 2>&1
fi